﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Infrastructure.Helpers
{
    public sealed class Converter
    {
        private static volatile Converter instance;
        private static object syncRoot = new Object();

        private Converter() { }

        public static Converter Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new Converter();
                    }
                }
                return instance;
            }
        }

        public ObservableCollection<T> ToObservableCollection<T>(IEnumerable<T> enumerableList)
        {
            if (enumerableList != null)
            {
                //create an emtpy observable collection object
                var observableCollection = new ObservableCollection<T>();

                //loop through all the records and add to observable collection object
                foreach (var item in enumerableList)
                    observableCollection.Add(item);

                //return the populated observable collection
                return observableCollection;
            }
            return null;
        }
    }
}
